package com.zygh.interactiveplatform.module.controller;


import com.alibaba.fastjson.JSONObject;
import com.zygh.interactiveplatform.common.anno.PcLog;
import com.zygh.interactiveplatform.common.constant.SwaggerTagConst;
import com.zygh.interactiveplatform.common.domain.ResponseDTO;
import com.zygh.interactiveplatform.module.entity.UserRole;
import com.zygh.interactiveplatform.module.service.UserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lee
 * @since 2021-01-28
 */
@RestController
@RequestMapping("/user-role")
@Api(tags = {SwaggerTagConst.Admin.MANAGER_USERROLE})
public class UserRoleController {
    @Resource
    private UserRoleService userRoleService;

    @ApiOperation(value = "权限新增", notes = "权限新增")
    @PostMapping("addUserRole")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_USERROLE, content = "权限新增")
    public ResponseDTO addUserRole(@RequestBody @Valid UserRole userRole) {
        return userRoleService.addUserRole(userRole);
    }

    @ApiOperation(value = "权限修改", notes = "权限修改")
    @PostMapping("updateUserRole")
    @PcLog(logType = "3", module = SwaggerTagConst.Admin.MANAGER_USERROLE, content = "权限修改")
    public ResponseDTO updateUserRole(@RequestBody @Valid UserRole userRole) {
        return userRoleService.updateUserRole(userRole);
    }

    @ApiOperation(value = "权限删除", notes = "权限删除")
    @PostMapping("deleteUserRole")
    @PcLog(logType = "4", module = SwaggerTagConst.Admin.MANAGER_USERROLE, content = "权限删除")
    public ResponseDTO deleteUserRole(@RequestBody String id) {
        String s = JSONObject.parseObject(id).get("id").toString();
        Integer new_id = Integer.parseInt(s);
        return userRoleService.deleteUserRole(new_id);
    }

    @ApiOperation(value = "查询所有权限", notes = "查询所有权限")
    @GetMapping("findUserRoleAll")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_USERROLE, content = "查询所有权限")
    public ResponseDTO findUserRoleAll(Integer current, Integer size) {
        return userRoleService.findUserRoleAll(current,size);
    }



}
